import { createDecorator } from 'vue-class-component';
// 延迟到Mounted节点绑定watch
const WatchMounted = (path, options?) => {
    if (options === void 0) {
        options = {};
    }
    const _a = options.deep;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const deep = _a === void 0 ? false : _a;
    const _b = options.immediate;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const immediate = _b === void 0 ? false : _b;
    return createDecorator(function (componentOptions, handler) {
        const mounted: Function = (componentOptions as any).mounted || new Function();
        function mergeFunction(Function) {
            if (Function) {
                return function () {
                    mounted.apply(this);
                    Function(this);
                };
            }
            return mounted;
        }
        (componentOptions as any).mounted = mergeFunction((Vue) => {
            Vue.$nextTick(() => {
                Vue.$watch(path, Vue[handler], options);
            });
        });
    });
};
// 派发名称装饰器
const DistributeName = (componentName) => {
    return createDecorator(function (componentOptions, handler) {
        const options = componentOptions as any;
        options.props['dt_key'] = { required: false };
        options.componentName = componentName;
        const created: Function = (componentOptions as any).created || new Function();
        function mergeFunction(Function) {
            if (Function) {
                return function () {
                    created.apply(this);
                    Function(this);
                };
            }
            return created;
        }
        options.created = mergeFunction((_this) => {
            // _this.dt_key && _this.$on(_this.dt_key, _this[handler])
            _this.$on(_this.dt_key || 'allComponent', _this[handler]);
        });
    });
};
export { WatchMounted, DistributeName };
